<?php

/**
 * security actions.
 *
 * @package    bde
 * @subpackage security
 * @author     Benjamin Herlin
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class securityActions extends sfActions
{
	/**
	 * Executes index action
	 *
	 * @param sfRequest $request A request object
	 */
	public function executeIndex(sfWebRequest $request)
	{
		$this->forward('default', 'module');
	}

	public function executeLogin(sfWebRequest $request)
	{
		if ($request->isMethod(sfWebRequest::POST))
		{
			$form = new LoginForm();
			
			$form->bind($request->getParameter('login'));
			
			if ($form->isValid())
			{
				$id_arise = $form->getValue('id_arise');
				
				/*$params = array(
					'firstname' => 'mmh'
				);*/
				$params = array();
				$this->getUser()->login($id_arise, $params);
				
				$this->getUser()->setFlash('info', "Vous êtes désormas identifié en tant que ".$id_arise.".");
				$this->redirect('homepage');
			}
			else
			{
				
			}
		}
		else
		{
			// Pas de formulaire posté, on affiche le formulaire de login
			$this->loginform = new LoginForm();
		}
	}
	
	public function executeLogout(sfWebRequest $request)
	{
		$this->getUser()->logout();
		$this->getUser()->setFlash('info', "Vous être maintenant déconnecté.");
		$this->redirect('homepage');
	}
}
